﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using LMSemir.Common;
using LMSemir.Entity;
using LMSemir.DAC;

namespace LMSemir.Backstage
{
    public partial class signin : System.Web.UI.Page
    {
        private const string semirKey = "?oC??~??";
        private const string lmsemirKey = "?D?{?4?";

        protected void Page_Load(object sender, EventArgs e)
        {
            string userName = WebUtils.GetFormValue("username", "");
            string password = WebUtils.GetFormValue("pwd", "");
            string strOP = WebUtils.GetPramaValue("op", "");
            if (!string.IsNullOrEmpty(strOP) && strOP == "signout")
            {
                UserEntity.IsLogin = false;
                this.Response.Cookies.Clear();
            }
            else if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(password))
            {
                string strPWD = userName.IndexOf("semiradmin") > -1 ? Encrypt.MD5Encrypt(password, semirKey) : Encrypt.MD5Encrypt(password, lmsemirKey);

                UserEntity user = UserDataAccess.GetUserInfo(userName, strPWD);
                if (!string.IsNullOrEmpty(user.UID.ToString())
                    && !string.IsNullOrEmpty(user.UserName)
                    && !string.IsNullOrEmpty(user.Password))
                {
                    Session["uid"] = user.UID;
                    Session["uname"] = user.UserName;
                    UserEntity.IsLogin = true;
                    this.Response.Redirect("admin.aspx");
                }
            }
        }
    }
}